#!/usr/bin/env python # coding=utf-8 
# File Name: RunPush.py
# Author: Bill Zhang
# Mail: zchcandid@gmail.com 
# Created Time: Tue 29 Oct 2013 07:26:32 PM CST

from pushData import Run
from pushData import MysqlConnect
 
import time
i=1
message="Begin pushing........\n"
message=message+"The amount of data having pushing: \n"
print(message)

#get the times of brand id
timesDb=MysqlConnect("pushLog")
Select=timesDb.cursor(buffered=True)
timesQuery="SELECT times FROM mouser WHERE LOG LIKE '{&quotErrorCode&quot:-100%'"
Select.execute(timesQuery)    
times=Select.fetchone()
while(times):
    StartTime=time.strftime('%H:%M:%S',time.localtime(time.time()))
    S="Start time:"+str(StartTime)
    print(S)
    interval=500
#    "avnet","chaoguang","futureW","future","pinjia","PromateSZ","quanding","Yosun"
    Dbase='mouser' 
    times=int(times[0])
    returnCode=Run(times,interval,Dbase)
    if(returnCode==404):
        time.sleep(1800)
        print("Try after 30min:")
        continue
    if(returnCode==0):
        print("Having Done!!!!!")
        times=0
    print("-")
    print(times)
   # times=times+1
    times=Select.fetchone()
    EndTime=time.strftime('%H:%M:%S',time.localtime(time.time()))
    E="End time:"+str(EndTime)
    print(E)
